[SQL]Summing a column while ignoring duplicate records(row_number())


SELECT custid, SUM(amount)
FROM (SELECT t.*,
             ROW_NUMBER() OVER (PARTITION BY custid, transid ORDER BY transid) AS seqnum
      FROM table_1 t
     ) t
WHERE seqnum = 1;
#SQL






你可能感興趣的文章

Ruby 沒有 i++ (increment operator)

Ruby 沒有 i++ (increment operator)

Intersection Observer API 使用筆記

Intersection Observer API 使用筆記

用 ES6 語法串接 API - Fetch

用 ES6 語法串接 API - Fetch






留言討論